﻿@{
    Layout = null;
}
@model ElingOA6_Admin_DSJCJ.Model.PrvGroup
<!DOCTYPE html>
<html>
<head>
    <title>用户组</title>
    @Html.Partial("LoadPanelPartial")
    @if (false)
    {
        <script src="../../../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../../../Scripts/ASPxScriptIntelliSense.js" type="text/javascript"></script>
    }
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/jquery-ui.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/jquery-ui.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/FloatDiv.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/regex.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Common/GetRootPath.ashx", true)" type="text/javascript"></script>

    <link href="@Url.Content("~/Scripts/dynatree/skin/ui.dynatree.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/dynatree/jquery.dynatree.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/json2.js", true)" type="text/javascript"></script>

    @Html.DevExpress().GetStyleSheets(

    new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme }
    )
    @Html.DevExpress().GetScripts(
        new Script { ExtensionType = ExtensionType.ListBox }
    )
       <style type="text/css">
        ul.dynatree-container
        {
            padding: 0px;
        }
    </style>

    <script type="text/javascript">
        var dataUser = @Html.Raw(Json.Encode(ViewData["treeJsonStrOrgUser"]));
        if (dataUser!="")
            {
                dataUser=JSON.parse(dataUser);
            }
            else
            {
                dataUser=null;
            }
        var dataFunc = @Html.Raw(Json.Encode(ViewData["treeJsonStrUserFunc"]));
        if (dataFunc!="")
            {
                dataFunc=JSON.parse(dataFunc);
            }
            else
            {
                dataFunc=null;
            }
        
    </script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("#toolMenu").smartFloat();
            $("#tabs").tabs();

            $("#orgUserTree").dynatree({
                clickFolderMode: 1,
                selectMode: 3,
                children: dataUser,
                keyboard: false,
                checkbox: true,
                onClick: function (node) {
                },
                onPostInit: function (isReloading, isError) {
                }
            });

            $("#userFuncTree").dynatree({
                clickFolderMode: 1,
                selectMode: 3,
                children: dataFunc,
                keyboard: false,
                checkbox: true,
                onClick: function (node) {
                },
                onPostInit: function (isReloading, isError) {
                },
                onActivate: function (node) {
                    if (node != null) {
                        $("#lblCurrentFuncName").text(node.data.title);
                        bindFunctionUserTree(node.data.key);
                    }
                    
                }
            });

            $("#functionUserTree").dynatree({
                clickFolderMode: 1,
                selectMode: 3,
                keyboard: false,
                checkbox: false
            });

            var hdResult = $("#hdResult").val();
            if (hdResult == "SUCCESS") {
                var hdMethodFromType = $("#hdMethodFromType").val();
                switch (hdMethodFromType) {
                    case "EDIT":
                        {
                            var groupName = $("#txtFGroupName").val();
                            parent.refreshNodeName(groupName);
                            break;
                        }

                    case "ADD":
                        {
                            var groupName = $("#txtFGroupName").val();
                            var hdGroupID = $("#hdGroupID").val();
                            parent.refreshSameLevelNode(groupName, hdGroupID);
                            break;
                        }
                }
            }

            var hdjsAlert = $("#hdjsAlert").val();
            if (hdjsAlert != "") {
                alert(hdjsAlert);
            }
        });
        function bindFunctionUserTree(functionNo) {
            lp.Show();
            $.ajax({
                type: "GET",
                url: rootPath + "/Admin/EmplGroup/GetFunctionUser",
                data: { functionNo: functionNo },
                async: true,
                success: function (jsonstr) {
                    if (jsonstr != "") {
                        var dataFuncUser = JSON.parse(jsonstr);
                        $("#functionUserTree").dynatree("option", "children", dataFuncUser);
                        $("#functionUserTree").dynatree("getTree").reload();
                       
                    }
                    lp.Hide();
                }
            });



        }

        /*保存*/
        function save() {
            if (FGroupNo.GetText() == "") {
                alert("组编号不能为空");
                FGroupNo.Focus();
                return;
            }
            if (FGroupName.GetText() == "") {
                alert("组名称不能为空");
                FGroupName.Focus();
                return;
            }

            //用户组权限
            var selNodes = $("#userFuncTree").dynatree("getTree").getSelectedNodes(false);
            var selKeys = $.map(selNodes, function (node) {
                return node.data.key;
            });
            var partsel = new Array();
            var userFuncTree = $("#userFuncTree").dynatree("getTree");
            $(".dynatree-partsel:not(.dynatree-selected)").each(function () {
                var node = $.ui.dynatree.getNode(this);
                if (userFuncTree.getNodeByKey(node.data.key)) {
                    partsel.push(node.data.key);
                }
            });

            selKeys = selKeys.concat(partsel);

            $("#hdFunctionSelect").val(selKeys);

            //用户组成员
            selNodes = $("#orgUserTree").dynatree("getTree").getSelectedNodes(false);
            selKeys = $.map(selNodes, function (node) {
                if (node.data.isFolder != true) {
                    return node.data.key;
                }
            });
            $("#hdOrgUserSelect").val(selKeys);

            lpModal.Show();
            form1.submit();

        }
        /*增加*/
        function addGroup() {
            lp.Show();
            window.location.href = rootPath + "/Admin/EmplGroup/AddGroup";
        }
        /*删除*/
        function deleteGroup() {
            var groupName = FGroupName.GetText();
            var hdFGroupIDEn = $("#hdFGroupIDEn").val();
            if (confirm("确定删除【" + groupName + "】吗？")) {
                $.ajax({
                    type: "POST",
                    url: rootPath + "/Admin/EmplGroup/DeleteGroup",
                    data: { groupIDEn: hdFGroupIDEn },
                    async: true,
                    success: function (jsonstr) {
                        var msg = jsonstr.split('|');
                        if (msg[0] == "SUCCESS") {
                            alert("删除成功");
                            parent.afterDeleteNode();
                        }
                        else {
                            if (msg.length > 1) {
                                alert(msg[1]);
                            }
                        }
                    }
                });
            }
        }

        function MenuTop_emClick(source, e) {
            switch (e.item.name) {
                case "btnSave":
                    {
                        //保存
                        save();
                        break;
                    }
                case "btnAdd":
                    {
                        //增加同级
                        addGroup();
                        break;
                    }

                case "btnDelete":
                    {
                        //删除
                        deleteGroup();
                        break;
                    }
            }
        }
    </script>

</head>
<body>
    @using (Html.BeginForm("Save", "EmplGroup", FormMethod.Post, new { id = "form1", @class = "edit_form" }))
    {
        <div class="floatToolMenu" id="toolMenu" style="z-index: 99;">
            <iframe style="position: absolute; visibility: inherit; top: 0px; left: 0px; width: 100%;
                height: 28px; z-index: -1; background-color: #00CCFF; border-width: 0px; filter='progid:dximagetransform.microsoft.alpha(style=0,opacity=0)';">
            </iframe>
            @Html.DevExpress().Menu(settings =>
       {
           settings.Name = "toolBarMenu";
           settings.ItemAutoWidth = false;
           settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
           settings.Styles.Style.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
           settings.Styles.Style.BorderTop.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
           settings.Items.Add(item =>
           {
               item.Name = "btnSave";
               item.Text = "保存";
               item.ClientEnabled = true;
               item.Image.Url = Url.Content("~/Content/ControlImages/filesave.png");

           });
           settings.Items.Add(item =>
           {
               item.Name = "btnAdd";
               item.Text = "新增";
               item.ClientEnabled = true;
               item.Image.Url = Url.Content("~/Content/ControlImages/edit_add.png");

           });
           settings.Items.Add(item =>
           {
               item.Name = "btnDelete";
               item.Text = "删除";
               item.ItemStyle.ForeColor = System.Drawing.Color.Red;
               item.ClientEnabled = true;
               item.Image.Url = Url.Content("~/Content/ControlImages/cancel.png");

           });
           settings.ClientSideEvents.ItemClick = "function(source,e){MenuTop_emClick(source,e)}";
           settings.ItemLinkMode = ItemLinkMode.ContentBounds;
       }).GetHtml()
        </div>
        <div>
            <table align="center" class="tableFrom">
                <tr>
                    <th>
                        <font color='red'>*</font>@Html.DevExpress().Label(settings => { settings.Text = "组编号:"; }).GetHtml()
                    </th>
                    <td>
                        @Html.DevExpress().TextBox(settings =>
                   {
                       settings.Name = "FGroupNo";
                       settings.Width = 100;
                       settings.Text = Model.FGroupNo;
                       settings.ReadOnly = Model.FGroupNo != null ? true : false;
                   }).GetHtml()
                    </td>
                    <th>
                        <font color='red'>*</font>@Html.DevExpress().Label(settings => { settings.Text = "组名称:"; }).GetHtml()
                    </th>
                    <td>
                        @Html.DevExpress().TextBox(settings =>
                   {
                       settings.Name = "FGroupName";
                       settings.Width = 220;
                       settings.Text = Model.FGroupName;
                   }).GetHtml()
                    </td>
                    <th>
                        @Html.DevExpress().Label(settings => { settings.Text = "说明:"; }).GetHtml()
                    </th>
                    <td>
                        @Html.DevExpress().TextBox(settings =>
                   {
                       settings.Name = "FNote";
                       settings.Width = 100;
                       settings.Text = Model.FNote;
                   }).GetHtml()
                    </td>
                </tr>
            </table>
        </div>
        <div id="tabs" class="div">
            <ul>
                <li><a href="#tabFunction">用户组权限</a></li>
                <li><a href="#orgUserTree">用户组成员</a></li>
            </ul>
            <div id="tabFunction" style="height: 550px">
                <div id="userFuncTree" style="height: 550px; width: 50%; float: left">
                </div>
                <div id="userFunctreeRight" style="height: 550px; width: 40%; float: left; margin-left: 50px">
                    <table>
                        <tr>
                            <td>
                                当前菜单【<label id="lblCurrentFuncName"></label>】已选用户： </td>
                        </tr>
                        <tr>
                            <td>
                                <div id="functionUserTree" style="height: 530px; width: 100%;">
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div id="orgUserTree">
            </div>
        </div>
        @Html.Hidden("hdGroupID", ViewData["groupID"]);
        @Html.Hidden("hdFunctionSelect", "");
        @Html.Hidden("hdOrgUserSelect", "");
        @Html.Hidden("hdMethod", ViewData["hdMethod"]);
        @Html.Hidden("hdResult", ViewData["result"]);
        @Html.Hidden("hdFGroupIDEn", Model.FGroupIDEn);
        @Html.Hidden("hdjsAlert", (ViewData["jsAlert"]));
        @Html.Hidden("hdloginIDs", (ViewData["loginIDs"]));
        @Html.Hidden("hdfunctionNOs", (ViewData["functionNOs"])); 
        @Html.Hidden("hdFocusKey", ViewData["focusKey"]);
    }
</body>
</html>
